﻿<Vignette:UCViewerCore x:Name="uCViewerCore"
                       x:Class="Rio.Framework.Pages.Viewer.ListVignetteSearch"
                       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                       xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                       xmlns:local="clr-namespace:Rio.Framework.Pages.UserControls"
                       xmlns:Vignette="clr-namespace:Rio.Framework.Pages.Viewer;assembly=Rio.Framework.Pages"
                       xmlns:Converter="clr-namespace:Rio.Framework.Pages.Helpers"
                       xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
                       xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
                       xmlns:ToolKit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
                       xmlns:dragDrop="clr-namespace:Telerik.Windows.Controls.DragDrop;assembly=Telerik.Windows.Controls"
                       xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
                       xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                       xmlns:behaviors="clr-namespace:Rio.Framework.Pages.AppCode.Helpers.Behavior"
                       xmlns:RioCommonControls="clr-namespace:Rio.Framework.Pages.Controls;assembly=Rio.Framework.Pages"
                       mc:Ignorable="d"
                       d:DesignHeight="400"
                       d:DesignWidth="350"
                       Loaded="UCViewerCore_Loaded">

    <UserControl.Resources>
        <Converter:ByteArrayToBitmapImageConverter x:Key="ByteArrayToBitmapImageConverter" />
        <Converter:PathFileToFileNameConverter x:Key="PathFileToFileNameConverter" />
        <Converter:PathFileToFileNameConverterWithoutExtension x:Key="PathFileToFileNameConverterWithoutExtension" />
        <Converter:ExtractExtensionConverter x:Key="ExtractExtensionConverter" />

        <Style TargetType="ListBoxItem"
               x:Key="draggableListBoxItem">
            <Setter Property="dragDrop:RadDragAndDropManager.AllowDrag"
                    Value="True" />
            <Setter Property="dragDrop:RadDragAndDropManager.AllowDrop"
                    Value="True" />
            <Setter Property="HorizontalAlignment"
                    Value="Center" />
            <Setter Property="VerticalAlignment"
                    Value="Center" />
        </Style>

        <Style x:Key="WrapPanelStyle"
               TargetType="ToolKit:WrapPanel">
            <Setter Property="Background">
                <Setter.Value>
                    <LinearGradientBrush EndPoint="0.5,1"
                                         StartPoint="0.5,0">
                        <GradientStop Color="#CF484848"
                                      Offset="0" />
                        <GradientStop Color="#DBADADAD"
                                      Offset="1" />
                        <GradientStop Color="#ADA7A7A7"
                                      Offset="0.401" />
                        <GradientStop Color="#F3AAAAAA"
                                      Offset="0.709" />
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
        </Style>

        <Style TargetType="ListBox"
               x:Key="draggableListBox">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBox">
                        <Border x:Name="ListBoxBorder"
                                CornerRadius="2"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}">
                            <vsm:VisualStateManager.VisualStateGroups>
                                <vsm:VisualStateGroup x:Name="DragCue">
                                    <vsm:VisualState x:Name="NoDrop" />
                                    <vsm:VisualState x:Name="DropPossible">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DropCueElement"
                                                                           Storyboard.TargetProperty="(UIElement.Visibility)">
                                                <DiscreteObjectKeyFrame KeyTime="0:0:0"
                                                                        Value="Visible" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ListBoxBorder"
                                                                           Storyboard.TargetProperty="(Border.BorderBrush)">
                                                <DiscreteObjectKeyFrame KeyTime="0:0:0"
                                                                        Value="Orange" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </vsm:VisualState>
                                    <vsm:VisualState x:Name="DropImpossible" />
                                </vsm:VisualStateGroup>
                            </vsm:VisualStateManager.VisualStateGroups>
                            <ScrollViewer Padding="{TemplateBinding Padding}"
                                          Background="{TemplateBinding Background}"
                                          BorderBrush="Transparent"
                                          BorderThickness="0">
                                <Grid>
                                    <ItemsPresenter />
                                    <Grid x:Name="DropCueElement"
                                          HorizontalAlignment="Left"
                                          VerticalAlignment="Top"
                                          IsHitTestVisible="False"
                                          Margin="0,5,0,0"
                                          dragDrop:RadDragAndDropManager.AllowDrop="True"
                                          Visibility="Collapsed">
                                        <Rectangle Width="5"
                                                   Height="{Binding Value, ElementName=SliderResizeThumb}"
                                                   HorizontalAlignment="Center"
                                                   IsHitTestVisible="False"
                                                   Fill="LightGreen" />
                                    </Grid>
                                </Grid>
                            </ScrollViewer>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="ItemContainerStyle"
                    Value="{StaticResource draggableListBoxItem}" />
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <ToolKit:WrapPanel Style="{StaticResource WrapPanelStyle}" />
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="ItemTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Border BorderBrush="{Binding IsFullSearch}"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                MouseLeftButtonDown="Item_MouseLeftButtonDown">
                            <local:Thumbnail Title="{Binding OriginalName,Converter={StaticResource PathFileToFileNameConverter}}"
                                             Icon="{Binding OriginalName, Converter={StaticResource ExtractExtensionConverter}}"
                                             ImageSource="{Binding Img, Converter={StaticResource ByteArrayToBitmapImageConverter}}"
                                             NumberPages="{Binding NumberPages}"
                                             IsCutedOrCopied="{Binding IsCutedOrCopied}"
                                             IsFulltext="{Binding IsFullSearch}"
                                             WorkflowState="{Binding WorkflowState}"
                                             Width="{Binding Value, ElementName=SliderResizeThumb}"
                                             Height="{Binding Value, ElementName=SliderResizeThumb}">
                                
                                <ToolTipService.ToolTip>
                                    <ToolTip>
                                        <TextBlock Name="NameVignette"
                                                   Text="{Binding OriginalName,Converter={StaticResource PathFileToFileNameConverter}}"
                                                   TextWrapping="Wrap"
                                                   VerticalAlignment="Center"
                                                   HorizontalAlignment="Left" />
                                    </ToolTip>
                                </ToolTipService.ToolTip>
                            </local:Thumbnail>
                        </Border>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!--Drag and drop template-->
        <DataTemplate x:Name="DargAndDropTemplate">
            <telerik:RadDockPanel>
                <Border HorizontalAlignment="Center"
                        VerticalAlignment="Center">
                    <local:Thumbnail Title="{Binding OriginalName, Converter={StaticResource PathFileToFileNameConverter}}"
                                     Icon="{Binding OriginalName, Converter={StaticResource ExtractExtensionConverter}}"
                                     ImageSource="{Binding Img, Converter={StaticResource ByteArrayToBitmapImageConverter}}"
                                     NumberPages="{Binding NumberPages}"
                                     IsCutedOrCopied="{Binding IsCutedOrCopied}"
                                     WorkflowState="{Binding WorkflowState}"
                                     Width="128"
                                     Height="128">
                        
                        <ToolTipService.ToolTip>
                            <ToolTip>
                                <TextBlock Name="NameVignette"
                                           Text="{Binding OriginalName,Converter={StaticResource PathFileToFileNameConverter}}"
                                           TextWrapping="Wrap"
                                           VerticalAlignment="Center"
                                           HorizontalAlignment="Left" />
                            </ToolTip>
                        </ToolTipService.ToolTip>
                    </local:Thumbnail>
                </Border>
            </telerik:RadDockPanel>
        </DataTemplate>

        <LinearGradientBrush x:Key="SelectedModeColorBrush"
                             EndPoint="0.5,1"
                             StartPoint="0.5,0">
            <GradientStop Color="#FFCCFFCC"
                          Offset="0.022" />
            <GradientStop Color="#FFCCFF66"
                          Offset="0.536" />
            <GradientStop Color="#FFCCFF00"
                          Offset="0.728" />
        </LinearGradientBrush>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot"
          Background="White">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"
                              MinWidth="150" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*"/>
            <RowDefinition Height="30"/>
        </Grid.RowDefinitions>
        
        <RioCommonControls:DocumentContextMenu x:Name="DocumentContextMenu" ViewMode="Thumbnail"/>
        
        <!--Ribbon bar -->
        <RioCommonControls:DocumentRibbonBar x:Name="DocumentToolbar" ViewMode="Thumbnail" />

        <TextBlock Name="TextBlockMode"
                   FontSize="16"
                   Grid.Row="1"
                   Grid.ColumnSpan="3"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Center"
                   FontWeight="Bold"
                   Foreground="Black"
                   Canvas.ZIndex="99" />
        
        <ListBox  Name="ListBoxVignette"
                  Style="{StaticResource draggableListBox}"
                  Grid.Row="1"
                  Grid.Column="0"
                  Grid.ColumnSpan="3"
                  HorizontalContentAlignment="Center"
                  SelectionMode="Extended"
                  SelectionChanged="ListBoxVignette_SelectionChanged"
                  ItemsSource="{Binding ListItemSource, ElementName=uCViewerCore, Mode=TwoWay}">

            <telerikNavigation:RadContextMenu.ContextMenu>
                <telerikNavigation:RadContextMenu>

                </telerikNavigation:RadContextMenu>
            </telerikNavigation:RadContextMenu.ContextMenu>
            
            <i:Interaction.Behaviors>
                <behaviors:AutoScrollBehavior />
            </i:Interaction.Behaviors>
        
        </ListBox>

        <StackPanel Grid.Column="0" Grid.Row="2" Background="#FF8D8D8D" HorizontalAlignment="Stretch">
            <telerikNavigation:RadToolBar x:Name="RadMenu"
                                      VerticalAlignment="Stretch"
                                      BorderThickness="1" 
                                      Background="#FF8D8D8D"
                                      HorizontalAlignment="Right" 
                                      HorizontalContentAlignment="Right" 
                                      FlowDirection="LeftToRight">

                <telerikNavigation:RadMenuItem x:Name="ThumbResize"
                                           IsEnabled="true" Background="{x:Null}" OpacityMask="Black" BorderBrush="{x:Null}" Foreground="{x:Null}">
                    <telerikNavigation:RadMenuItem.Header>
                        <telerik:RadSlider x:Name="SliderResizeThumb"
                                       Maximum="350"
                                       Minimum="160"
                                       Width="200"
                                       Value="224"
                                       IsSnapToTickEnabled="True"
                                       TickFrequency="32"
                                       Margin="0,0,30,0"
                                       TickPlacement="TopLeft" BorderBrush="Black" Background="Black" Foreground="Black" OpacityMask="{x:Null}" LargeChange="1" FlowDirection="LeftToRight" IsMoveToPointEnabled="True" IsSelectionRangeEnabled="False" IsDeferredDraggingEnabled="False" IsDirectionReversed="False" IsTabStop="True" Orientation="Horizontal" />
                    </telerikNavigation:RadMenuItem.Header>

                </telerikNavigation:RadMenuItem>

            </telerikNavigation:RadToolBar>
        </StackPanel>
        
    </Grid>
</Vignette:UCViewerCore>
